Skip to content

Conversation

@pierremtb
Copy link
Contributor

@pierremtb pierremtb commented Oct 22, 2025

Closes #8636, needed for #8565

And make it vitest testable!

@vercel
Copy link

vercel bot commented Oct 22, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
modeling-app Ready Ready Preview Comment Oct 22, 2025 4:33pm

cmdBar,
}) => {
const initialCode = `@settings(defaultLengthUnit = in, experimentalFeatures = allow)
const initialCode = `@settings(defaultLengthUnit = in)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how I discovered this in #8565

toast.success(
`Updated file experimental features level to ${level.type}`
)
const newAst = setExperimentalFeatures(level)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this to act like other code mods, returning the new ast to be updated the regular way, instead of just a code execution.

Comment on lines 3783 to 3791
// Remove once this command isn't experimental anymore
let astWithNewSetting: Node<Program> | undefined
if (kclManager.fileSettings.experimentalFeatures?.type !== 'Allow') {
const result = await setExperimentalFeatures({ type: 'Allow' })
if (err(result)) {
return Promise.reject(result)
const ast = setExperimentalFeatures({ type: 'Allow' })
if (err(ast)) {
return Promise.reject(ast)
}

astWithNewSetting = ast
Copy link
Contributor Author

@pierremtb pierremtb Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the problematic part in Hole. Now, since we return an ast like other codemods, we don't even have to run two executions here, but rather pass it directly to the actual codemod, see below

Comment on lines -156 to -167

export async function setExperimentalFeatures(
level: WarningLevel
): Promise<void | Error> {
const newCode = changeExperimentalFeatures(codeManager.code, level)
if (err(newCode)) {
return new Error(`Failed to set experimental features: ${newCode.message}`)
}
codeManager.updateCodeStateEditor(newCode)
await codeManager.writeToFile()
await kclManager.executeCode()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to settings.ts

* Change the meta settings for the kcl file.
* @returns the new kcl string with the updated settings.
*/
export function changeExperimentalFeatures(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing anything here, but making it possible to run in vitest

@pierremtb pierremtb marked this pull request as ready for review October 22, 2025 16:34
@pierremtb pierremtb requested a review from a team as a code owner October 22, 2025 16:34
describe('settings.spec.ts', () => {
describe('Testing setExperimentalFeatures', () => {
it('should add the annotation and set the flag if not present', async () => {
const instance = await loadAndInitialiseWasmInstance(WASM_PATH)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perfection

return newCode
}

const result = parse(newCode, instance)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love how we need a wrapper function on the TS side to parse the result of setting the @settings() that we then need to test. I was trying to make the interface be the KCL source, but it seems like we're just not there yet. Might be better to parse on the Rust side of the boundary. It doesn't prevent the recast-and-parse, but it would save a trip across the wasm boundary.

As it is isn't fundamentally wrong, though.

@pierremtb pierremtb merged commit ff1edf1 into main Oct 23, 2025
57 checks passed
@pierremtb pierremtb deleted the pierremtb/issue8636-race-condition-exp-features branch October 23, 2025 14:53
franknoirot pushed a commit that referenced this pull request Oct 24, 2025
* Fix race condition with setExperimentalFeatures
Closes #8636, needed for #8565

* Move to a codemod file, do proper dep injection, add unit tests

* Lint

* Lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix race condition coming out of setExperimentalFeatures

3 participants